import openpyxl, pprint
import census2010


def readcensusdata():
    wb = openpyxl.load_workbook("censuspopdata.xlsx")
    sheets = wb.sheetnames
    print(sheets)
    sheet = wb['Population by Census Tract']
    countyData = {}
    for row in range(2, sheet.max_row + 1):
        state = sheet['B' + str(row)].value
        countyData.setdefault(state, {})
        # print(state)
        county = sheet['C' + str(row)].value
        countyData[state].setdefault(county, {'tracts': 0, 'pop': 0})
        # print(county)
        pop = sheet['D' + str(row)].value
        countyData[state][county]['tracts'] += 1
        countyData[state][county]['pop'] = int(pop)
        # print(pop)
    file = open('census2010.py', 'w')
    file.write('alldata = ' + pprint.pformat(countyData))
    file.close()


def showcensusData(state, county):
    print(census2010.alldata[state][county])


showcensusData('AK', 'Anchorage')
showcensusData('WY', 'Campbell')
